package org.helgoboss.document_database

/**
 * This trait defines the interface used to get access to a Database object. Actually, it's a kind of factory applied in a very functional way
 * for making sure the database object is always properly closed.
 *
 * A UseDatabase object is intended to be used like this:
 * <pre>
 * {@code
 * val name = useDatabase { db =>
 *     // ...
 * }
 * </pre>
 */
trait UseDatabase {
    /**
     * Creates a unique database object (= a connection to the database) and passes it to the given function. As soon as the function
     * finishes, the database object is properly closed.
     */
    def apply[T](f: (Database) => T): T
}